*****************************************************************************************************************************
********** THIS .DO FILE PRODUCES FIGURE 1 (Visual presentation of RD Estimates of the effect of a left-wing mayor) *********
*****************************************************************************************************************************

clear *

* call program to make rd graphs
do "${root}/codes/analysis/programs/rdgraph_prog.do"

*** PRODUCE GRAPHS

use "${root}/data/processed/final_sample.dta", clear
set scheme plotplain

* add back means to residualized variables, for better interpretation
foreach variable in tot_exp_avg_pc tot_exp_avg_sgdp tot_rev_avg_pc tot_rev_avg_sgdp current_exp_avg_share investments_avg_share personnel_avg_share social_exp_avg_share {
	sum `variable'
	replace res_`variable'=res_`variable'+`r(mean)'
}

foreach pcvar in tot_exp_avg_pc tot_rev_avg_pc {
	replace res_`pcvar'=res_`pcvar'/100
	}

keep if baseline_sample == 1

** SIZE OF GOV'T
* expenditure per capita
rdgraph res_tot_exp_avg_pc margin_mayor_left, title("RD Plot - spending per capita") name(tot_exp_avg_pc) ytitle("Log expenditure per capita") yaxisopt("ylabel(7.84(0.01)7.90) yscale(range(7.84 7.90))")/* xtitle("Left margin of victory")*/ pos(11) legend(yes)

* expenditure as a share of GDP
rdgraph res_tot_exp_avg_sgdp margin_mayor_left, title("RD Plot - spending (% of GDP)") name(tot_exp_avg_sgdp) ytitle("Spending (% of GDP)") /* xtitle("Left margin of victory")*/ pos(11)

* revenues per capita
rdgraph res_tot_rev_avg_pc margin_mayor_left, title("RD Plot - revenues per capita") name(tot_rev_avg_pc) ytitle("Log revenues per capita") yaxisopt("ylabel(7.95(0.01)8.00) yscale(range(7.95 8.00))")/*xtitle("Left margin of victory")*/ pos(11)

* revenues as a share of GDP
rdgraph res_tot_rev_avg_sgdp margin_mayor_left, title("RD Plot - revenues (% of GDP)") name(tot_rev_avg_sgdp) ytitle("Revenues (% of GDP)") yaxisopt("ylabel(20(1)25) yscale(range(20 25))")/*xtitle("Left margin of victory")*/ pos(11)


graph combine tot_exp_avg_pc tot_exp_avg_sgdp tot_rev_avg_pc tot_rev_avg_sgdp, xcommon row(2) cols(2) b1(Left margin of victory)
graph export "${root}/results/figures/size_of_gov.pdf", replace

** BUDGET CATEGORIES
* current expenditure
rdgraph res_current_exp_avg_share margin_mayor_left, title("RD Plot - current expenditure share)") name(current_exp_avg_share) ytitle("Current expenditure") yaxisopt("ylabel(86(1)90) yscale(range(86 90)) ")/*xtitle("Left margin of victory")*/ pos(11)

* public investment
rdgraph res_investments_avg_share margin_mayor_left, title("RD Plot - public investment share") name(investments_avg_share) ytitle("Public investment") yaxisopt("ylabel(9(1)12) yscale(range(9 12)) ")/*xtitle("Left margin of victory")*/ pos(11)

* personnel
rdgraph res_personnel_avg_share margin_mayor_left, title("RD Plot - personnel share") name(personnel_avg_share) ytitle("Personnel") yaxisopt("ylabel(46(1)50) yscale(range(46 50)) ") /*xtitle("Left margin of victory")*/ pos(11)

** FUNCTIONAL CATEGORIES
* social expenditures
rdgraph res_social_exp_avg_share margin_mayor_left, title("RD Plot - social expenditures share") name(social_exp_fe) ytitle("Social expenditures") yaxisopt("ylabel(58(1)60) yscale(range(57.5 60.5)) ") /*xtitle("Left margin of victory")*/ pos(11)


graph combine current_exp_avg_share investments_avg_share personnel_avg_share social_exp_fe, xcommon row(2) cols(2) b1(Left margin of victory)
graph export "${root}/results/figures/composition.pdf", replace
